package de.lmu.ifi.pst.uwejsf.framework.process;

import java.util.ArrayList;
import java.util.List;

import de.lmu.ifi.pst.uwejsf.framework.AbstractUWEContextFactory;
import de.lmu.ifi.pst.uwejsf.framework.NavigationRule;
import de.lmu.ifi.pst.uwejsf.framework.UWEHelpers;

public abstract class MainProcessClassBean extends ProcessClassBean {

	protected List<NavigationRule> navigationRules = new ArrayList<NavigationRule>();

	public MainProcessClassBean(String activityName, String userActionName) {
		super(activityName, userActionName);

	}

	public MainProcessClassBean(String activityName) {
		super(activityName);

	}

	public void addNavigationRule(NavigationRule navigationRule) {
		navigationRules.add(navigationRule);
	}

	public List<NavigationRule> getNavigationRules() {
		return navigationRules;
	}

	public Object getUWEInput() {
		if (activeContentSelector == null)
			activeContentSelector = defaultContentSelector;
		if (activeContentSelector == null) {
			if (contentSelectors.values().size() > 0)
				activeContentSelector = contentSelectors.values().iterator()
						.next();
		}
		if (activeContentSelector == null)
			return null;

		Object rawContent = activeContentSelector
				.getContent(AbstractUWEContextFactory.getCurrentInstance());
		Object result = null;

		// get rid of wrappers!
		if (rawContent instanceof List)
			result = UWEHelpers.convertListContent(rawContent, Object.class);
		else
			result = UWEHelpers.convertSingleContent(rawContent, Object.class);
		return result;
	}

	public Object getResult() {
		return getActivityBean().getResult();
	}

	public String getOutcome() {
		return getActivityBean().getOutcome();
	}

}
